﻿{include file='pub/header'/}
<title>产品分类</title>
</head>
<body>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
            </a>
        </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort">
            <thead>
            <tr class="text-c">
                <th width="40"><input name="" type="checkbox" value=""></th>
                <th width="80">ID</th>
                <th width="100">分类名称</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $cateList as $list}
            <tr class="text-c">
                <td><input name="ids[]" type="checkbox" value="{$list.id}"></td>
                <td>{$list.id}</td>
                <td>{$list.name}</td>
                <td class="td-manage">
                    <a style="text-decoration:none" class="ml-5" onClick="category_del(this,'{$list.id}')" href="javascript:;" title="删除">
                        <i class="Hui-iconfont">&#xe6e2;</i>删除
                    </a>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
</div>

{include file="pub/footer"/}
<script type="text/javascript">

    //批量删除分类
    function datadel() {
        var idNode = $("tbody input[type='checkbox']:checked");
        var ids = '';
        $.each(idNode, function (i, v) {
            ids += $(v).val() + ",";
        });
        ids = ids.substr(0, ids.length - 1);
        layer.confirm('确定删除选中分类，并同时删除当前分类下的子分类？', function (res) {
            $.post('{:url("Products/delCate")}', {ids: ids}, function (res) {
                if (res.code == 1) {
                    idNode.parent().parent().remove();
                    layer.msg('操作成功', {icon: 6, time: 1000});
                } else {
                    layer.msg('操作失败');
                }
            });
        });

    }
    /*分类-删除*/
    function category_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: '{:url("Products/delCate")}',
                data: {ids: id},
                dataType: 'json',
                success: function (data) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>